package orchestration.android.parcelable;

import java.util.HashMap;
import java.util.Set;

import orchestration.businessprocess.model.BPAnnotation;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

public class ParcelableAnnotation extends BPAnnotation implements Parcelable{

	

	public ParcelableAnnotation(String id, String source) {
		super(id, source);
	}

	public ParcelableAnnotation(String id, String source,
			HashMap<String, String> details) {
		super(id, source, details);
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		HashMap<String, String> details = getDetails();
		Set<String> keySet = details.keySet();
		Bundle b= new Bundle();
		for(String key : keySet)
			b.putString(key, details.get(key));
		dest.writeString(getId());
		dest.writeString(getSource());
		dest.writeStringArray((String[])keySet.toArray());
		dest.writeBundle(b);
	}
	
	public static final Parcelable.Creator<ParcelableAnnotation> CREATOR
    = new Parcelable.Creator<ParcelableAnnotation>() {
		public ParcelableAnnotation createFromParcel(Parcel in) {
		    String id= in.readString();
		    String source=in.readString();
		    String[] keys= in.createStringArray();
		    Bundle b= in.readBundle();
		    
		    HashMap<String,String> details=new HashMap<String, String>();
		    for(String key : keys)
		    	details.put(key, b.getString(key));
		    return new ParcelableAnnotation(id, source,details);
		}
		
		public ParcelableAnnotation[] newArray(int size) {
		    return new ParcelableAnnotation[size];
		}
	};



	@Override
	public int describeContents() {
		return 0;
	}}
